﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;

namespace SchoolManagementSystem.Report._2._ThuQuy
{
   public class SoQuyReportData
    {
        public  static DataTable LoadCashBook(string Search="", int SodudaukyVN=0, int SodudaukyUSD=0)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.VoucherService.GetListCashBook(Search +" order by CreateDate");

            foreach (var item in data)
            {
                
               
                 if(item.ReceiptNo.Contains("PTHP"))
                 {
                     if (item.Fee == 0)
                     {
                         item.MoneyThuUSD = "";
                         item.MoneyThuVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Fee);
                             if (item.Fee == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN += item.Fee;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                                 item.MoneyThuVNInt = item.Fee;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Fee);
                             if (item.Fee == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD += item.Fee;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                                item.MoneyInStockVN = SodudaukyVN;
                                 item.MoneyThuUSDInt = item.Fee;
                                 item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                     
                     
                 }
                 else if (item.ReceiptNo.Contains("PTDC"))
                 {
                     if (item.Sale == 0)
                     {
                         item.MoneyThuUSD = "";
                         item.MoneyThuVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Sale);
                             if (item.Sale == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN += item.Sale;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyThuVNInt = item.Sale;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Sale);
                             if (item.Sale == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD += item.Sale;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyThuUSDInt = item.Sale;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }

                 }
                 else if (item.ReceiptNo.Contains("PTCH"))
                 {
                     if (item.Apartment == 0)
                     {
                         item.MoneyThuUSD = "";
                         item.MoneyThuVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Apartment);
                             if (item.Apartment == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN += item.Apartment;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyThuVNInt = item.Apartment;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Apartment);
                             if (item.Apartment == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD += item.Apartment;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyThuUSDInt = item.Apartment;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                 }
                 else if (item.ReceiptNo.Contains("PTNB"))
                 {
                     if (item.Local == 0)
                     {
                         item.MoneyThuUSD = "";
                         item.MoneyThuVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Local);
                             if (item.Local == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN += item.Local;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyThuVNInt = item.Local;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Local);
                             if (item.Local == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD += item.Local;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyThuUSDInt = item.Local;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                 }
                 else if (item.ReceiptNo.Contains("PTSL"))
                 {
                     if (item.Salon == 0)
                     {
                         item.MoneyThuUSD = "";
                         item.MoneyThuVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Salon);
                             if (item.Salon == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN += item.Salon;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyThuVNInt = item.Salon;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Salon);
                             if (item.Salon == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD += item.Salon;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyThuUSDInt = item.Salon;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                 }
                 else if (item.ReceiptNo.Contains("PCCH"))
                 {
                     if (item.PayApartment == 0)
                     {
                         item.MoneyChiUSD = "";
                         item.MoneyChiVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyChiVN = Helper.StringHelper.FormatVND(item.PayApartment);
                             if (item.PayApartment == 0)
                             {
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN -= item.PayApartment;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyChiVNInt = item.PayApartment;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                         else
                         {
                             item.MoneyChiUSD = Helper.StringHelper.FormatCurrencyUS(item.PayApartment);
                             if (item.PayApartment == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD -= item.PayApartment;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyChiUSDInt = item.PayApartment;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                 }
                 else if (item.ReceiptNo.Contains("PCT"))
                 {
                     if (item.PaySchool == 0)
                     {
                         item.MoneyChiUSD = "";
                         item.MoneyChiVN = "";
                     }
                     else
                     {
                         if (item.MoneyType == 0)
                         {
                             item.MoneyChiVN = Helper.StringHelper.FormatVND(item.PaySchool);
                             if (item.PaySchool == 0)
                             {

                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyVN -= item.PaySchool;
                                 }
                                 item.MoneyInStockVN = SodudaukyVN;
                             }
                             item.MoneyInStockUSD = SodudaukyUSD;
                             item.MoneyChiVNInt = item.PaySchool;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);

                         }
                         else
                         {
                             item.MoneyChiUSD = Helper.StringHelper.FormatCurrencyUS(item.PaySchool);
                             if (item.Fee == 0)
                             {
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             else
                             {
                                 if (item.PaymentMethod == 1)
                                 {
                                     SodudaukyUSD -= item.PaySchool;
                                 }
                                 item.MoneyInStockUSD = SodudaukyUSD;
                             }
                             item.MoneyInStockVN = SodudaukyVN;
                             item.MoneyChiUSDInt = item.PaySchool;
                             item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                         }
                     }
                 }
                 else //truong hop ma phieu ko co thi defaul la phieu thu hoc phi
                 {
                     //if (item.PaySchool == 0)
                     //{
                     //    item.MoneyChiUSD = "";
                     //    item.MoneyChiVN = "";
                     //}
                     //else
                     //{
                     //    if (item.MoneyType == 0)
                     //    {
                     //        item.MoneyChiVN = Helper.StringHelper.FormatVND(item.PaySchool);
                     //        if (item.PaySchool == 0)
                     //        {

                     //            item.MoneyInStockVN = SodudaukyVN;
                     //        }
                     //        else
                     //        {
                     //            if (item.PaymentMethod == 1)
                     //            {
                     //                SodudaukyVN -= item.PaySchool;
                     //            }
                     //            item.MoneyInStockVN = SodudaukyVN;
                     //        }
                     //        item.MoneyInStockUSD = SodudaukyUSD;
                     //        item.MoneyChiVNInt = item.PaySchool;
                     //        item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);

                     //    }
                     //    else
                     //    {
                     //        item.MoneyChiUSD = Helper.StringHelper.FormatCurrencyUS(item.PaySchool);
                     //        if (item.Fee == 0)
                     //        {
                     //            item.MoneyInStockUSD = SodudaukyUSD;
                     //        }
                     //        else
                     //        {
                     //            if (item.PaymentMethod == 1)
                     //            {
                     //                SodudaukyUSD -= item.PaySchool;
                     //            }
                     //            item.MoneyInStockUSD = SodudaukyUSD;
                     //        }
                     //        item.MoneyInStockVN = SodudaukyVN;
                     //        item.MoneyChiUSDInt = item.PaySchool;
                     //        item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                     //    }
                 }
                
            }

            var l = new KList<CoreData.VwCashBook>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }



        public static DataTable LoadCashBookFull(string Search = "", int SodudaukyVN = 0, int SodudaukyUSD = 0)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.VoucherService.GetListCashBook(Search + " order by CreateDate");

            ////xử ly tách dòng
            //var tempdata = new List<CoreData.VwCashBook>();
            //foreach (var item in data)
            //{
            //    if(item
            //}


            //tính toán lại
            foreach (var item in data)
            {


                if (item.ReceiptNo.Contains("PTHP"))
                {
                    if (item.Fee == 0)
                    {
                        item.MoneyThuUSD = "";
                        item.MoneyThuVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Fee);
                            if (item.Fee == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN += item.Fee;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyThuVNInt = item.Fee;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Fee);
                            if (item.Fee == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD += item.Fee;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyThuUSDInt = item.Fee;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);

                        }
                    }


                }
                if (item.ReceiptNo.Contains("PTDC"))
                {
                    if (item.Sale == 0)
                    {
                        item.MoneyThuUSD = "";
                        item.MoneyThuVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Sale);
                            if (item.Sale == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN += item.Sale;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyThuVNInt = item.Sale;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Sale);
                            if (item.Sale == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD += item.Sale;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyThuUSDInt = item.Sale;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }

                }
                if (item.ReceiptNo.Contains("PTCH"))
                {
                    if (item.Apartment == 0)
                    {
                        item.MoneyThuUSD = "";
                        item.MoneyThuVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Apartment);
                            if (item.Apartment == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN += item.Apartment;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyThuVNInt = item.Apartment;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Apartment);
                            if (item.Apartment == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD += item.Apartment;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyThuUSDInt = item.Apartment;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }
                }
                if (item.ReceiptNo.Contains("PTNB"))
                {
                    if (item.Local == 0)
                    {
                        item.MoneyThuUSD = "";
                        item.MoneyThuVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Local);
                            if (item.Local == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN += item.Local;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyThuVNInt = item.Local;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Local);
                            if (item.Local == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD += item.Local;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyThuUSDInt = item.Local;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }
                }
                if (item.ReceiptNo.Contains("PTSL"))
                {
                    if (item.Salon == 0)
                    {
                        item.MoneyThuUSD = "";
                        item.MoneyThuVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyThuVN = Helper.StringHelper.FormatVND(item.Salon);
                            if (item.Salon == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN += item.Salon;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyThuVNInt = item.Salon;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyThuUSD = Helper.StringHelper.FormatCurrencyUS(item.Salon);
                            if (item.Salon == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD += item.Salon;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyThuUSDInt = item.Salon;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }
                }
                if (item.ReceiptNo.Contains("PCCH"))
                {
                    if (item.PayApartment == 0)
                    {
                        item.MoneyChiUSD = "";
                        item.MoneyChiVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyChiVN = Helper.StringHelper.FormatVND(item.PayApartment);
                            if (item.PayApartment == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN -= item.PayApartment;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyChiVNInt = item.PayApartment;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                        else
                        {
                            item.MoneyChiUSD = Helper.StringHelper.FormatCurrencyUS(item.PayApartment);
                            if (item.PayApartment == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD -= item.PayApartment;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyChiUSDInt = item.PayApartment;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }
                }
                if (item.ReceiptNo.Contains("PCT"))
                {
                    if (item.PaySchool == 0)
                    {
                        item.MoneyChiUSD = "";
                        item.MoneyChiVN = "";
                    }
                    else
                    {
                        if (item.MoneyType == 0)
                        {
                            item.MoneyChiVN = Helper.StringHelper.FormatVND(item.PaySchool);
                            if (item.PaySchool == 0)
                            {
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyVN -= item.PaySchool;
                                }
                                item.MoneyInStockVN = SodudaukyVN;
                            }
                            item.MoneyInStockUSD = SodudaukyUSD;
                            item.MoneyChiVNInt = item.PaySchool;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);

                        }
                        else
                        {
                            item.MoneyChiUSD = Helper.StringHelper.FormatCurrencyUS(item.PaySchool);
                            if (item.Fee == 0)
                            {
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            else
                            {
                                if (item.PaymentMethod == 1)
                                {
                                    SodudaukyUSD -= item.PaySchool;
                                }
                                item.MoneyInStockUSD = SodudaukyUSD;
                            }
                            item.MoneyInStockVN = SodudaukyVN;
                            item.MoneyChiUSDInt = item.PaySchool;
                            item.MoneyInStockVNString = Helper.StringHelper.FormatVND(item.MoneyInStockVN);
                        }
                    }
                }

            }

            var l = new KList<CoreData.VwCashBook>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

    }
}
